package com.ftg.micsofteware.config;

import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 布衣
 */
@RestControllerAdvice
public class GloabException {

    /**
     * 全局化异常处理类
     * @param e  异常
     * @return
     */
    @ExceptionHandler(Exception.class)
    public String handleException(Exception e) {
        String msg = "";
        if (e instanceof FlowException) {
            msg = "请求被限流了";
        } else if (e instanceof ParamFlowException) {
            msg = "请求被热点参数限流";
        } else if (e instanceof DegradeException) {
            msg = "请求被降级了";
        } else if (e instanceof AuthorityException) {
            msg = "没有权限访问";
        }
        msg += "   全局异常处理器判断得到";
        return msg;
    }
}
